package com.gujia.concurrent.reentrant;

import java.util.concurrent.locks.ReentrantLock;

public class Warehouse {

    private boolean isFull;
    private ReentrantLock lock = new ReentrantLock();

    public void put(){


            if(isFull){
                try{
                    lock.lock();
                            System.out.println("空了，放商品");

                        isFull = !isFull;



                    }catch (Exception e){
                        e.printStackTrace();
                    }finally {
                        lock.unlock();
                    }
            }

    }

    public  void get(){


         if (!isFull){
             try{
                 lock.lock();
                 System.out.println("满了，取商品");
                  isFull = !isFull;


            }catch (Exception e){
                e.printStackTrace();
            }finally {
                lock.unlock();
            }
         }
    }





}
